<?php
/**
 * Conversations - A lightweight BB for Xaraya
 *
 * @package modules
 * @copyright (C) 2003-2006 The Digital Development Foundation.
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @link http://www.xaraya.com
 *
 * @subpackage conversations
 * @link http://xaraya.com/index.php/release/760.html
 * @author John Cox
 * @author jojodee
*/
function conversations_user_updateconfig()
{
   
    // We need to grab our array early since we are going to be doing this on a one by one basis
    $consettings = xarModGetVar('conversations', 'settings');
    if (!empty($consettings)) {
        $settings = unserialize($consettings);
    }
    
    // Set our ML VAR as well
    $result = xarML('Your configuration is set to') . ' : ';
    
    // TODO: define these defaults in ONE place only.
    xarVarFetch('threshlow','int:1:',$threshlow,'',XARVAR_NOT_REQUIRED);
    xarVarFetch('threshmed','int:1:',$threshmed,'',XARVAR_NOT_REQUIRED);            
    xarVarFetch('threshtop','int:1:',$threshtop,'',XARVAR_NOT_REQUIRED);
    xarVarFetch('fresh','int:1:',$fresh,'',XARVAR_NOT_REQUIRED);
    xarVarFetch('initial','int:1:',$initial,'',XARVAR_NOT_REQUIRED);
    xarVarFetch('supportshorturls','checkbox', $supportshorturls, false, XARVAR_NOT_REQUIRED);

    
    // default settings for xarbb
    //$settings['threshlow'] = $threshlow;
    //$settings['threshmed'] = $threshmed;
    //$settings['threshtop'] = $threshtop;
    //$settings['fresh']     = $fresh;
    //$settings['initial']   = $initial;
    
    if (!empty($threshmed)){
        $settings['threshmed'] = $threshmed;
        xarModSetVar('conversations', 'settings', serialize($settings));
        return $result . $threshmed;
    }
    
    if (!empty($threshlow)){
        $settings['threshlow'] = $threshlow;
        xarModSetVar('conversations', 'settings', serialize($settings));
        return $result . $threshlow;
    }

    if (!empty($threshtop)){
        $settings['threshtop'] = $threshtop;
        xarModSetVar('conversations', 'settings', serialize($settings));
        return $result . $threshtop;
    }
    if (!empty($fresh)){
        $settings['fresh'] = $fresh;
        xarModSetVar('conversations', 'settings', serialize($settings));
        return $result . $fresh;
    }
    if (!empty($initial)){
        $settings['initial'] = $initial;
        xarModSetVar('conversations', 'settings', serialize($settings));
        return $result . $initial;
    }

    // Short URLS are just set.  Why even have an option?
    
    
    // Do this in a bit
    //if (!xarVarFetch('modulealias','checkbox', $modulealias,false,XARVAR_NOT_REQUIRED)) return;

    /*
    if (isset($aliasname) && trim($aliasname)<>'') {
        xarModSetVar('xarbb', 'useModuleAlias', $modulealias);
    } else{
        xarModSetVar('xarbb', 'useModuleAlias', 0);
    }
    */

    // Module alias for short URLs
   //$currentalias = xarModGetVar('xarbb','aliasname');
   //$newalias = trim($aliasname);
   /* Get rid of the spaces if any, it's easier here and use that as the alias*/
   /*if ( strpos($newalias,'_') === FALSE )
   {
       $newalias = str_replace(' ','_',$newalias);
   }
   $hasalias= xarModGetAlias($currentalias);
   $useAliasName= xarModGetVar('xarbb','useModuleAlias');

   if (($useAliasName==1) && !empty($newalias)){*/
       /* we want to use an aliasname */
       /* First check for old alias and delete it */
       //if (isset($hasalias) && ($hasalias =='xarbb')){
       //    xarModDelAlias($currentalias,'xarbb');
       //}
       /* now set the new alias if it's a new one */
       //xarModSetAlias($newalias,'xarbb');
   //}
   /* now set the alias modvar */
   //xarModSetVar('xarbb', 'aliasname', $newalias);


    // call modifyconfig hooks with module
    //$hooks = xarModCallHooks('module', 'updateconfig', 'conversations', 
     //   array('module' => 'conversations'));
    //$data['hooks'] = $hooks;
}          
?>           